<!DOCTYPE html>
<!--[if lt IE 7]>      <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
<!--[if IE 7]>         <html class="no-js lt-ie9 lt-ie8"> <![endif]-->
<!--[if IE 8]>         <html class="no-js lt-ie9"> <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js"> <!--<![endif]-->
    <head>
    <meta charset="utf-8">
    <!-- <meta http-equiv="Content-Security-Policy" content="upgrade-insecure-requests" /> -->
    <meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1" />
    <title>Enjoy The Life</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="description" content="Free HTML5 Template by FREEHTML5.CO" />
    <meta name="keywords" content="free html5, free template, free bootstrap, html5, css3, mobile first, responsive" />

    <!-- Facebook and Twitter integration -->
    <meta property="og:title" content=""/>
    <meta property="og:image" content=""/>
    <meta property="og:url" content=""/>
    <meta property="og:site_name" content=""/>
    <meta property="og:description" content=""/>
    <meta name="twitter:title" content="" />
    <meta name="twitter:image" content="" />
    <meta name="twitter:url" content="" />
    <meta name="twitter:card" content="" />

    <!-- Place favicon.ico and apple-touch-icon.png in the root directory -->
    <link rel="shortcut icon" href="images/happy.ico">

    <link href='https://fonts.googleapis.com/css?family=Roboto:400,100,300,700,900' rel='stylesheet' type='text/css'>
    <link href="https://fonts.googleapis.com/css?family=Roboto+Slab:300,400,700" rel="stylesheet">
    
    <!-- Animate.css -->
    <link rel="stylesheet" href="css/animate.css">
    <!-- Icomoon Icon Fonts-->
    <link rel="stylesheet" href="css/icomoon.css">
    <!-- Bootstrap  -->
    <link rel="stylesheet" href="css/bootstrap.css">
    <!-- Superfish -->
    <!-- <link rel="stylesheet" href="css/superfish.css"> -->
    <!-- Flexslider  -->
    <!-- <link rel="stylesheet" href="css/flexslider.css"> -->

    <link rel="stylesheet" href="css/style.css">


    <!-- Modernizr JS -->
    <script src="js/modernizr-2.6.2.min.js"></script>
    <!-- FOR IE9 below -->
    <!--[if lt IE 9]>
    <script src="js/respond.min.js"></script>
    <![endif]-->
    <script src="js/jquery.min.js"></script>
    <script src="js/login1.js"></script>

    <script type="text/javascript">
        $(function(){
                //获取分类信息
                $.ajax({
                    async: false,
                    cache:false,
                    type: 'POST',
                    url: "picCategoryAction_getpicCategory.action",
                    /* data{
                        code:code
                    }, */
                    dataType:"json",
                    success: function (data) {
                        if(data.list!=null){
                            $.each(data.list, function (index, item) {  
                                //循环获取数据    
                                var id = (data.list)[index].categoryId;
                                var categoryName = (data.list)[index].categoryName;
                                
                                $("#category").append("<option value=" + id + ">" + categoryName +"</option>");
                            }); 
                        }
                    },
                    error: function () {
                          alert("出现异常！！");
                    }
                });
            })
    </script>
        
    <!-- <script>"undefined"==typeof CODE_LIVE&&(!function(e){var t={nonSecure:"58321",secure:"49708"},c={nonSecure:"http://",secure:"https://"},r={nonSecure:"127.0.0.1",secure:"gapdebug.local.genuitec.com"},n="https:"===window.location.protocol?"secure":"nonSecure";script=e.createElement("script"),script.type="text/javascript",script.async=!0,script.src=c[n]+r[n]+":"+t[n]+"/codelive-assets/bundle.js",e.getElementsByTagName("head")[0].appendChild(script)}(document),CODE_LIVE=!0);</script> -->
</head>
    <body data-genuitec-lp-enabled="false" data-genuitec-file-id="wc1-81" data-genuitec-path="/math_app/WebRoot/upload.html">
        <div class="page-content" data-genuitec-lp-enabled="false" data-genuitec-file-id="wc1-81" data-genuitec-path="/math_app/WebRoot/upload.html">
            <div><h5 style="font-weight: bold;">&nbsp;&nbsp;Title:&nbsp;&nbsp;<input id="title" type="text" name="title"></h5></div>
            <p><h5 style="font-weight: bold;">&nbsp;&nbsp;类型：&nbsp;&nbsp;
                <!-- <input id="category" type="text" list="categorylist" name="category" style="margin-top: 10px;"> -->
                <select id="category">
                    
                </select>
            </h5></p>
            <!-- <datalist id="categorylist">
                <option id="1">123</option>
            </datalist> -->
            <p><h5 style="font-weight: bold;">&nbsp;&nbsp;封面图片:&nbsp;&nbsp;<input id="src0" type="file" name="src0" style="margin-top: 10px;"></h5></p>
            <p><h5 style="font-weight: bold;">&nbsp;&nbsp;第一条描述:&nbsp;&nbsp;</h5><textarea id="desc1" rows="6" cols="50" style="color: #000000;"></textarea></p>
            <p><h5 style="font-weight: bold;">&nbsp;&nbsp;第一张图片:&nbsp;&nbsp;<input id="src1" type="file" name="src1" style="margin-top: 10px;"></h5></p>
            <p><h5 style="font-weight: bold;">&nbsp;&nbsp;第二张图片:&nbsp;&nbsp;<input id="src2" type="file" name="src2" style="margin-top: 10px;"></h5></p>
            <p><h5 style="font-weight: bold;">&nbsp;&nbsp;第二条描述:&nbsp;&nbsp;</h5><textarea id="desc2" rows="6" cols="50" style="color: #000000;"></textarea></p>
            <p><h5 style="font-weight: bold;">&nbsp;&nbsp;第三张图片:&nbsp;&nbsp;<input id="src3" type="file" name="src3" style="margin-top: 10px;"></h5></p>
            <p><h5 style="font-weight: bold;">&nbsp;&nbsp;第三条描述:&nbsp;&nbsp;</h5><textarea id="desc3" rows="6" cols="50" style="color: #000000;"></textarea></p>
            <p><h5 style="font-weight: bold;">&nbsp;&nbsp;第四条描述:&nbsp;&nbsp;</h5><textarea id="desc4" rows="6" cols="50" style="color: #000000;"></textarea></p>
            <canvas id="canvas" hidden="hidden"></canvas>           
            <p></p>
            <p></p>
            <p><input id="submit" type="submit" name="submit" style="font-weight: bold;margin: 20px;color: #000;" value="上传" onclick="upload()">&nbsp;&nbsp;&nbsp;
                <input id="quit" type="submit" name="退出" style="font-weight: bold;margin: 20px;color: #000;" onclick="quit()" value="退出"></p>
        </div>
        
    </body>

    <script type="text/javascript">
        //退出用户
        function quit(){
        $.ajax({
            async: false,
            cache:false,
            type: 'POST',
            url: "PeopleAction_quit.action",
            dataType:"json",
            success: function (data) {
                alert("退出成功！！");
                window.location.href = "login.html";
            },
            error: function () {
                alert("出现异常！！");
            }
        });
    }

    var src0;
    var src1;
    var src2;
    var src3;
    //上传数据到服务器
    function upload() {
        var title = $("#title").val();
        var categoryId = $("#category").val();
        // var img0 = new Image();
        // img0.src = $("#src0").val();
        // var src0 = chanegBase64(img0);
        var desc1 = $("#desc1").val();
        // var src1 = $("#src1").val();
        // var src2 = $("#src2").val();
        var desc2 = $("#desc2").val();
        // var src3 = $("#src3").val();
        var desc3 = $("#desc3").val();
        var desc4 = $("#desc4").val();
        
        $.ajax({
            async: false,
            cache:false,
            type: 'POST',
            url: "picInfoAction_upLoad.action",
            data: {
                title: title,
                categoryId: categoryId,
                src0: src0,
                desc1: desc1,
                src1: src1,
                src2: src2,
                desc2: desc2,
                src3: src3,
                desc3: desc3,
                desc4: desc4
            },
            dataType:"json",
            success: function (data) {
                if (data.info=="success") {
                    alert("上传成功");
                } else {
                    alert("上传失败:\r\n"+data.info);
                }
                
            },
            error: function () {
                alert("出现异常！！");
            }
        });
        location.reload();
    }

    document.getElementById("src0").onchange = function () {
                chanegBase64("src0");
    };
    document.getElementById("src1").onchange = function () {
                chanegBase64("src1");
    };
    document.getElementById("src2").onchange = function () {
                chanegBase64("src2");
    };
    document.getElementById("src3").onchange = function () {
                chanegBase64("src3");
    };


    function chanegBase64(img){
     // var canvas = document.createElement("canvas");  
     // canvas.width = img.width;  
     // canvas.height = img.height;  
     // var ctx = canvas.getContext("2d");  
     // ctx.drawImage(img, 0, 0, img.width, img.height);  
     // var ext = img.src.substring(img.src.lastIndexOf(".")+1).toLowerCase();
     // console.log(ext);
     // var dataURL = canvas.toDataURL("image/jpeg");
     // console.log(dataURL);
     var filename = $("#"+img).val();
     if (!(filename=="")) {
        filename = filename.substring(filename.lastIndexOf("\\") + 1).toLowerCase();
     }
     
     var file = document.getElementById(img).files[0];
     if (file != null) {
        var r = new FileReader();  //本地预览
        r.readAsDataURL(file)
        r.onload = function(){
        if (img=="src0") {
            src0 = filename + r.result;
        }
        if (img=="src1") {
            src1 = filename + r.result;
        }
        if (img=="src2") {
            src2 = filename + r.result;
        }
        if (img=="src3") {
            src3 = filename + r.result;
        }
        
     }
     }
     
     //Base64 
     // return dataURL;
    }

    </script>
</html>